package com.witdata.controller.auth;

import com.witdata.common.domain.Result;
import com.witdata.common.domain.Status;
import com.witdata.common.domain.dto.RoleDto;
import com.witdata.common.domain.dto.RolePermDto;
import com.witdata.common.domain.dto.RoleUserDto;
import com.witdata.common.service.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/auth/role")
public class RoleController {

    public final RoleService roleService;

    @PostMapping("/add")
    public Result<String> add(@RequestBody RoleDto roleDto) {
        roleService.saveRole(roleDto);
        return Result.ok(Status.ROLESAVESUCCESS);
    }

    @PostMapping("/perm/add")
    public Result<String> addPerm(@RequestBody RolePermDto rolePerm) {
        roleService.addPerm(rolePerm);
        return Result.ok(Status.ROLEPERMSAVESUCCESS);
    }

    @PostMapping("/user/add")
    public Result<String> addPerm(@RequestBody RoleUserDto roleUser) {
        roleService.addUser(roleUser);
        return Result.ok(Status.USERROLESAVESUCCESS);
    }

    @GetMapping("/list")
    public Result<List<RoleDto>> list() {
        List<RoleDto> roleList = roleService.getRoleList();
        return Result.ok(Status.SUCCESS, roleList);
    }

}
